//
//  YAYIEditResumeCell.m
//  多点执业
//
//  Created by hxp on 16/6/23.
//  Copyright © 2016年 hxp. All rights reserved.
//

#import "YAYIEditResumeCell.h"
#import "Masonry/Masonry.h"

#define YAYIFont(t) [UIFont systemFontOfSize:t]

@implementation YAYIEditResumeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}


-(void)createView{
    self.bgView = [UIView new];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.bgView];
    self.dotLabel = [UILabel new];
    self.dotLabel.frame = CGRectMake(0, 10, 4, 30);
    self.dotLabel.backgroundColor = [UIColor colorWithRed:83/255.0 green:165/255.0 blue:243/255.0 alpha:1];
    [self.bgView addSubview:self.dotLabel];
    
    self.titleLabel = [UILabel new];
    self.titleLabel.textColor = YAYIColor(83,165, 243);
    self.titleLabel.font = YAYIFont(14);
    [self.bgView addSubview:self.titleLabel];
    
    self.line = [UILabel new];
    self.line.backgroundColor = [UIColor lightGrayColor];
    _line.alpha = 0.4;
    [self.bgView addSubview:self.line];
    self.content = [UILabel new];
    self.content.numberOfLines = 0;
    self.content.font = YAYIFont(14);
   
    [self.bgView addSubview:self.content];
}


-(void)setContentString:(NSString *)contentString
{
    self.content.text = contentString;
    
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    
    CGFloat height = [self heightRowLabel:YAYIFont(14) content:self.content.text];
    
    [self.dotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.top.equalTo(@4);
        make.size.mas_equalTo(CGSizeMake(4, 30));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.dotLabel).with.offset(15);
        make.top.mas_equalTo(self.dotLabel.mas_top);
        make.size.mas_equalTo(CGSizeMake(100,30));
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(4);
        make.size.mas_equalTo(CGSizeMake(width, 0.3));
    }];
    
    [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.mas_equalTo(self.line.mas_bottom).with.offset(8);
        make.size.mas_equalTo(CGSizeMake(width - 20, height + 10));
    }];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.mas_equalTo(@10);
        make.size.mas_equalTo(CGSizeMake(width, 30 + 14+ 8+10 + height));
    }];
}


-(CGFloat)heightRowLabel:(UIFont *)font content:(NSString *)content{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(width - 0, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
    
    return size.height;
}

@end
